package com.kqb.auth.config;

import com.aliyun.captcha20230305.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 杉果树皮
 * @date 2025/4/17 10:11
 * @description: 验证码配置类
 */

@Configuration
@EnableConfigurationProperties(CaptchaProperties.class)
public class CaptchaConfig {


    @Autowired
    private CaptchaProperties captchaProperties;

    @Bean
    public Client client() {
        Config config = new Config();
        config.accessKeyId = captchaProperties.getAccessKeyId();
        config.accessKeySecret = captchaProperties.getAccessKeySecret();
        config.endpoint = captchaProperties.getEndpoint();
        config.connectTimeout = captchaProperties.getConnectTimeout();
        config.readTimeout = captchaProperties.getReadTimeout();
        try {
            return new Client(config);
        } catch (Exception e) {
            throw new RuntimeException("创建验证码客户端失败");
        }
    }

}
